home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PASCAL / 0195.ZIP / HEXFUNCT.LIB < prev    next >
Text File  |  1984-12-02  |  1KB  |  42 lines

  1. {@@@@@@@@@@@ copyright (C) 1984 by Neil J. Rubenking @@@@@@@@@@@@@@@@@@@@@@@@
  2. The purchaser of these procedures and functions may include them in COMPILED
  3. programs freely, but may not sell or give away the source text.}
  4.  
  5. type HexString = string[5];
  6. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  7. function Hex(num:integer):HexString;
  8.     {-----------------------------------------------------------}
  9.     function RealMod(RealNum:real;ModBy:integer):integer;
  10.     var
  11.       this, that : real;                     {A MODULO function for numbers}
  12.       begin                                  {too big to be integers.      }
  13.         this := trunc(realnum/modby);
  14.         that := ModBy*this;
  15.         RealMod := trunc(RealNum - that);
  16.       end;
  17.     {-----------------------------------------------------------}
  18.     function hexchar(N:byte):char;
  19.       begin
  20.         if N < 10 then hexchar := chr(N+48)
  21.           else hexchar := chr(N+55);
  22.       end;
  23.     {-----------------------------------------------------------}
  24. var
  25.   RealNum : real;
  26.   N, M : byte;
  27.   temp : Hexstring;
  28. begin
  29.   temp := '     ';
  30.   if num < 0 then RealNum := (65536. + num)
  31.      else RealNum := num;
  32.   for N := 5 downto 2 do
  33.     begin
  34.       M := RealMod(RealNum,16);
  35.       RealNum := trunc(RealNum/16);
  36.       temp[N] := hexchar(M);
  37.     end;
  38.   temp[1] := '$';
  39.   Hex := temp;
  40. end;
  41. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  42.